<template>
  <div class="lock-container">
    <div class="lock-form">
      <div>
        <h3 class="title">页面已锁屏，请输入锁屏密码</h3>
        <el-input
          placeholder="请输入锁屏密码"
          type="password"
          class="input-with-select"
          v-model="passwd"
          @keyup.enter.native="handleLogin"
        >
        </el-input>
        <div style="margin-top:20px;margin-left:150px;">
          <el-button @click="handleLogin">解锁</el-button>
          <el-button @click="handleLogout">退出</el-button>
        </div>
      </div>
    </div>
  </div>
</template>
<script>
export default {
  name: 'lock',
  data() {
    return {
      passwd: '',
      passwdError: false,
      pass: false
    }
  },
  created() {},
  mounted() {},
  computed: {},
  methods: {
    handleLogout() {
      this.$confirm('是否退出系统, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      })
        .then(() => {
          //删除vuex状态表
          this.$store.commit('CLEAR_LOCK')
          //清除session，回到登录页
          window.sessionStorage.clear()
          //删除user_token
          // util.removeStore('user_token')
          this.$router.push({
            path: '/login'
          })
        })
        .catch(() => {
          return false
        })
    },
    handleLogin() {
      console.log('this.lockPasswd', this.$store.state.lockPasswd)
      if (this.passwd !== this.$store.state.lockPasswd) {
        this.passwd = ''
        this.$message({
          message: '解锁密码错误,请重新输入',
          type: 'error'
        })
        this.passwdError = true
        setTimeout(() => {
          this.passwdError = false
        }, 1000)
        return
      }
      this.pass = true
      setTimeout(() => {
        //输入密码正确后删除vuex中状态值
        this.$store.commit('CLEAR_LOCK')
        this.$router.go(-1) //返回上一层
      }, 1000)
    }
  }
}
</script>

<style lang="less" scoped>
.lock-container {
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  .title {
    font-size: 20px;
    margin-bottom: 20px;
    color: #333;
  }
}
.lock-container::before {
  z-index: -999;
  content: '';
  position: absolute;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  background-image: url('../assets/login.png');
  background-size: cover;
}
.lock-form {
  width: 300px;
}
</style>
